package com.lanou.dllo.soccernews.fragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.lanou.dllo.soccernews.fragment.circle2fragment.Circle2Fragment;
import com.lanou.dllo.soccernews.fragment.circle2fragment.HotFragment;
import com.lanou.dllo.soccernews.fragment.circlefragment.CircleFragment;
import com.lanou.dllo.soccernews.fragment.collectionFragment.CollectionFragment;
import com.lanou.dllo.soccernews.fragment.datasfragment.EpLFragment;
import com.lanou.dllo.soccernews.fragment.deepfragment.DeepFragment;
import com.lanou.dllo.soccernews.fragment.homelinefragment.HeadlineFragment;
import com.lanou.dllo.soccernews.fragment.importantfragment.ImportantFragment;
import com.lanou.dllo.soccernews.fragment.shakefragment.ShakeFragment2;


/**
 * Created by dllo on 15/10/21.
 */
public class FragmentFactory {

    private static SparseArray<Fragment> fragmentMap = new SparseArray<>();
    private static SparseArray<Fragment> fragmentMap2 = new SparseArray<>();
    private static SparseArray<Fragment> fragmentMap3 = new SparseArray<>();
    private static SparseArray<Fragment> fragmentMap4= new SparseArray<>();
    public static Fragment createFragment(int position) {
        Fragment f = fragmentMap.get(position);
        if (f == null) {
            switch (position) {
                case 0:
                    f = new HeadlineFragment();

                    break;

                case 1:
                    f = new CircleFragment();
                    break;
                case 2:
                    f = new CollectionFragment();
                    break;
                case 3:
                    f = new DeepFragment();
                    break;
                case 4:
                    f = new ShakeFragment2();
                    break;
                default:
                    f = new DatasFragment();
                    break;

            }
            fragmentMap.put(position, f);

        }
        return f;

    }

    public static Fragment createFragment2(int position) {
        Fragment f = fragmentMap2.get(position);
        if (f == null) {
            switch (position) {
                case 0:
                    f = new ImportantFragment();

                    break;

                case 1:
                    f = new Fragment();
                    break;
                case 2:
                    f = new Fragment();
                    break;
                case 3:
                    f = new Fragment();
                    break;

                default:
                    f = new Fragment();
                    break;

            }
            fragmentMap2.put(position, f);

        }
        return f;

    }

    public static Fragment createFragment3(int position) {
        Fragment f = fragmentMap3.get(position);
        if (f == null) {
            switch (position) {
                case 0:
                    f = new Circle2Fragment();

                    break;

                case 1:
                    f = new HotFragment();
                    break;


                default:
                    f = new Fragment();
                    break;

            }
            fragmentMap3.put(position, f);

        }
        return f;

    }

    public static Fragment createFragment4(int position) {
        Fragment f = fragmentMap4.get(position);
        if (f == null) {
            switch (position) {
                case 0:
                    f = new EpLFragment();

                    break;

                case 1:
                    f = new Fragment();
                    break;
                case 2:
                    f = new Fragment();
                    break;
                case 3:
                    f = new Fragment();
                    break;
                case 4:
                    f = new Fragment();
                    break;
                default:
                    f = new Fragment();
                    break;

            }
            fragmentMap4.put(position, f);

        }
        return f;

    }
}
